package com.example.pkmedical.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.example.pkmedical.APP.MyApp;
import com.example.pkmedical.Activity.LockScreenActivity;
import com.example.pkmedical.Activity.PadLockActivity;
import com.example.pkmedical.Utils.CommandUtil;
import com.example.pkmedical.Utils.DateUtils;
import com.example.pkmedical.Utils.TimeUtils;

public class TimeChangeReceiver extends BroadcastReceiver {

    //    DateUtils.getTime(TimeUtils.getCurrentTimeMillis()),DateUtils.getTime(CommandUtil.STARTDATE),DateUtils.getTime(CommandUtil.STOPDATE)
    @Override
    public void onReceive(Context context, Intent intent) {
        if (CommandUtil.ISJISHI){
            switch (intent.getAction()) {
                case Intent.ACTION_TIME_TICK:

                    //每过一分钟 触发
                    if (DateUtils.isEffectiveDate2(TimeUtils.stringToDate(TimeUtils.getNowDataLock()), TimeUtils.stringToDate(CommandUtil.STARTDATE), TimeUtils.stringToDate(CommandUtil.STOPDATE))) {

                        Log.d("yangshuo", TimeUtils.stringToDate(TimeUtils.getNowDataLock()) + "---" + TimeUtils.stringToDate(CommandUtil.STARTDATE) + "在里面*******************");

                    } else {
                        Log.d("yangshuo", TimeUtils.stringToDate(TimeUtils.getNowDataLock()) + "---" + TimeUtils.stringToDate(CommandUtil.STOPDATE) + "不在里面*******************");
                        context.startActivity(new Intent(MyApp.getAppContext(), PadLockActivity.class));
                        CommandUtil.ISJISHI = false;
                        context.unregisterReceiver(this);
                    }
                    break;
//
//            case Intent.ACTION_TIME_CHANGED:
//
////设置了系统时间
//
//                Toast.makeText(context, "system time changed", Toast.LENGTH_SHORT).show();
//
//                break;
//
//            case Intent.ACTION_TIMEZONE_CHANGED:
//
////设置了系统时区的action
//
//                Toast.makeText(context, "system time zone changed", Toast.LENGTH_SHORT).show();
//
//                break;
            }
        }

    }
}
